using System;

namespace LFramework 
{
    public class ClockTimer : TimerBase
    {
        private float m_TotalTime;
        Action m_FinishCB;

        private float m_CurTime;

        public static ClockTimer Create(int id, Action finish_cb, float total_time) 
        {
            ClockTimer clockTimer = GameEntry.Pool.ClassObjectPool.Dequeue<ClockTimer>();
            clockTimer.Init(id, finish_cb, total_time);
            return clockTimer;
        }

        public void Init(int id,Action finish_cb, float total_time)
        {
            ID = id;
            m_FinishCB = finish_cb;
            m_TotalTime = total_time;
            m_CurTime = 0f;
        }

        public override void Update(float dt)
        {
            m_CurTime += dt;

            if (m_CurTime >= m_TotalTime)
            {
                m_FinishCB?.Invoke();
                IsFinished = true;
            }
        }

        public override void Restart()
        {
            m_CurTime = 0;
        }
    }
}

